package com.example.listener

import android.Manifest
import android.bluetooth.BluetoothManager
import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat

private const val TAG = "MainActivity"
class MainActivity : AppCompatActivity() {

    private val listOf =
        listOf(Manifest.permission.ACCESS_WIFI_STATE, Manifest.permission.ACCESS_FINE_LOCATION)


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val lackpermissions = listOf.filter { permission ->
            ActivityCompat.checkSelfPermission(
                this,
                permission
            ) != PackageManager.PERMISSION_GRANTED
        }
        if (lackpermissions.isNotEmpty()) {
            ActivityCompat.requestPermissions(this, lackpermissions.toTypedArray(), 10)
        }


        val manager: BluetoothManager? = ContextCompat.getSystemService(this, BluetoothManager::class.java)
        manager?.adapter?.apply {

            if (isEnabled.not()) {
                Log.i(TAG, "bluetooth is not enable.")
                val enable = enable()
                Log.i(TAG, "enable :$enable ")
            }
        }

    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)

    }
}